package com.google.code.jtasks.bugzilla;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;

import com.google.code.jtasks.bugzilla.proxy.bug.BugCommentsProxy.Comment;
import com.google.code.jtasks.bugzilla.proxy.bug.BugHistoryProxy.HistoryEntry;
import com.google.code.jtasks.bugzilla.proxy.bug.BugSearchProxy.Bug;
import com.google.code.jtasks.connection.TaskRepoId;

/**
 * Each {@link BugContainer} instance stores a single {@link Bug} with its associated {@link Comment}s and
 * {@link HistoryEntry}s.
 */
public final class BugContainer implements Serializable
{
	private static final long serialVersionUID = 6505373030638461660L;

	private final TaskRepoId taskRepoId;
	private final Bug bug;
	private final Collection<Comment> comments;
	private final Collection<HistoryEntry> historyEntries;

	/**
	 * Constructs a new {@link BugContainer} for the specified {@link Bug} and related data.
	 * 
	 * @param taskRepoId
	 *            the {@link TaskRepoId} identifying the task repository that the specified {@link Bug} is
	 *            part of
	 * @param bug
	 *            the {@link Bug} that will be stored in this {@link BugContainer}
	 * @param comments
	 *            the {@link Comment}s associated with this {@link BugContainer}'s {@link Bug}
	 * @param historyEntries
	 *            the {@link HistoryEntry}s associated with this {@link BugContainer}'s {@link Bug}
	 */
	public BugContainer(TaskRepoId taskRepoId, Bug bug, Collection<Comment> comments,
			Collection<HistoryEntry> historyEntries)
	{
		this.taskRepoId = taskRepoId;
		this.bug = bug;
		this.comments = Collections.unmodifiableCollection(comments);
		this.historyEntries = Collections.unmodifiableCollection(historyEntries);
	}

	/**
	 * Returns the {@link TaskRepoId} identifying the task repository that the specified {@link Bug} is part
	 * of.
	 * 
	 * @return the {@link TaskRepoId} identifying the task repository that the specified {@link Bug} is part
	 *         of
	 */
	public TaskRepoId getTaskRepoId()
	{
		return taskRepoId;
	}

	/**
	 * Returns the {@link Bug} stored in this {@link BugContainer}.
	 * 
	 * @return the {@link Bug} stored in this {@link BugContainer}
	 */
	public Bug getBug()
	{
		return this.bug;
	}

	/**
	 * Returns the {@link Comment}s associated with this {@link BugContainer}'s {@link Bug}.
	 * 
	 * @return the {@link Comment}s associated with this {@link BugContainer}'s {@link Bug}
	 */
	public Collection<Comment> getComments()
	{
		return comments;
	}

	/**
	 * Returns the {@link HistoryEntry}s associated with this {@link BugContainer}'s {@link Bug}.
	 * 
	 * @return the {@link HistoryEntry}s associated with this {@link BugContainer}'s {@link Bug}
	 */
	public Collection<HistoryEntry> getHistoryEntries()
	{
		return historyEntries;
	}
}
